home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / Æ Stream Library 1.0 / AEStream_CPlus.h < prev    next >
Text File  |  1991-09-27  |  4KB  |  109 lines

  1. ////
  2. ////    AEStream_CPlus.h        A (write-only) stream for creating AE Descriptors.
  3. ////                            This header file for use with C++. Use AEStream.h with C.
  4. ////
  5. ////    By Jens Alfke            ©1991 Apple Computer, Inc. All rights reserved.
  6. ////
  7.  
  8. // NOTE: This header file is for C++ programs only. If you #include "AEStream.h" in a C++ 
  9. //         program, you'll get this header anyway.
  10.  
  11.  
  12. // NOTE: In case of disagreement between this header and the C one (AEStream.h),
  13. //         this header is correct and the C header needs to be fixed.
  14.  
  15.  
  16. #ifndef __AESTREAM__
  17.     #define __AESTREAM__
  18.  
  19. #ifndef __MEMORY__
  20.     #include <Memory.h>
  21. #endif
  22. #ifndef __APPLEEVENTS__
  23.     #include <AppleEvents.h>
  24. #endif
  25.  
  26. const errAEStream_BadNesting    = 13579;    // Bad descriptor/array nesting error
  27.  
  28. //    Here are the C-style definitions, which are the actual functions implemented:
  29.  
  30. struct AEStream;
  31. struct AEStreamMark;
  32.  
  33. extern "C" {
  34.     OSErr
  35.         AEStream_Open        ( AEStream& ),
  36.         AEStream_Close        ( AEStream&, AEDesc *desc ),
  37.  
  38.         AEStream_WriteDesc    ( AEStream&, DescType type, const void *data, Size length ),
  39.         AEStream_WriteAEDesc( AEStream&, const AEDesc &desc ),
  40.  
  41.         AEStream_OpenDesc    ( AEStream&, DescType type, AEStreamMark &mark ),
  42.         AEStream_WriteData    ( AEStream&, const void *data, Size length ),
  43.         AEStream_CloseDesc    ( AEStream&,          const AEStreamMark &mark ),
  44.  
  45.         AEStream_OpenList    ( AEStream&,       AEStreamMark &mark ),
  46.         AEStream_CloseList    ( AEStream&, const AEStreamMark &mark ),
  47.  
  48.         AEStream_OpenRecord    ( AEStream&, DescType type, AEStreamMark &mark ),
  49.         AEStream_CloseRecord( AEStream&,          const AEStreamMark &mark ),
  50.  
  51.         AEStream_WriteKeyDesc(AEStream&, DescType key,
  52.                                             DescType type, const void *data, Size length ),
  53.         AEStream_OpenKeyDesc( AEStream&, DescType key, DescType type, AEStreamMark &mark ),
  54.         AEStream_WriteKey    ( AEStream&, DescType key );
  55. }
  56.  
  57. // Here are the data structures, complete with fancy C++ inline methods to call the above fns:
  58.  
  59.  
  60. struct AEStreamMark {    // Mark descriptor
  61.     Size    sizeIndex;
  62.     Size    countIndex;
  63. };
  64.  
  65. struct AEStream {        // A (write-only) stream on an AE descriptor
  66.     Handle    data;            // The data
  67.     Size    index;            // Current index (into data handle) to write to
  68.     AEStreamMark mark;        // Current mark: Index to size/length field of open desc/array/record
  69.     Size    size;            // Current size of handle
  70.     
  71.     AEStream();
  72.     ~AEStream();
  73.     
  74.     inline OSErr
  75.         Close        ( AEDesc *desc )
  76.                                                 {return AEStream_Close(*this,desc);}
  77.  
  78.         OpenDesc    ( DescType type, AEStreamMark &mark )
  79.                                                 {return AEStream_OpenDesc(*this,type,mark);}
  80.         WriteData    ( const void *data, Size length )
  81.                                                 {return AEStream_WriteData(*this,data,length);}
  82.         CloseDesc    ( const AEStreamMark &mark )
  83.                                                 {return AEStream_CloseDesc(*this,mark);}
  84.  
  85.         WriteDesc    ( DescType type, const void *data, Size length )
  86.                                                 {return AEStream_WriteDesc(*this,type,data,length);}
  87.         WriteDesc    ( const AEDesc &desc )
  88.                                                 {return AEStream_WriteAEDesc(*this,desc);}
  89.  
  90.         OpenList    (        AEStreamMark &mark )
  91.                                                 {return AEStream_OpenList(*this,mark);}
  92.         CloseList    ( const AEStreamMark &mark )
  93.                                                 {return AEStream_CloseList(*this,mark);}
  94.  
  95.         OpenRecord    ( DescType type, AEStreamMark &mark )
  96.                                                 {return AEStream_OpenRecord(*this,type,mark);}
  97.         CloseRecord    (            const AEStreamMark &mark )
  98.                                                 {return AEStream_CloseRecord(*this,mark);}
  99.  
  100.         WriteKeyDesc( DescType key, DescType type, void *data, Size length )
  101.                                         {return AEStream_WriteKeyDesc(*this,key,type,data,length);}
  102.         OpenKeyDesc    ( DescType key, DescType type, AEStreamMark &mark )
  103.                                                 {return AEStream_OpenKeyDesc(*this,key,type,mark);}
  104.         WriteKey    ( DescType key )
  105.                                                 {return AEStream_WriteKey(*this,key);}
  106. };
  107.  
  108.  
  109. #endif